package com.dmooo.yxmmerchant.view.model;

import android.content.Context;

import com.common.net.entity.SubjectPost;
import com.common.net.listener.HttpOnNextListener;
import com.common.net.subscribers.ProgressSubscriber;
import com.dmooo.yxmmerchant.http.HttpManager;
import com.dmooo.yxmmerchant.view.contract.CouponContract;

import java.util.HashMap;
import java.util.Map;

public class CouponModel implements CouponContract.CouponMdl {
    private Context context;
    public CouponModel(Context context) {
        this.context=context;
    }

    @Override
    public void addCoupon(String token, String name, String money, String condition_money, String all_num, String limit_num,
                          String send_start_time, String send_end_time, String use_start_time, String use_end_time, String type, String goods_id, HttpOnNextListener listener) {
        Map<String,Object> map=new HashMap<>();
        map.put("token",token);
        map.put("name",name);
        map.put("money",money);
        map.put("condition_money",condition_money);
        map.put("all_num",all_num);
        map.put("limit_num",limit_num);
        map.put("send_start_time",send_start_time);
        map.put("send_end_time",send_end_time);
        map.put("use_start_time",use_start_time);
        map.put("use_end_time",use_end_time);
        map.put("type",type);
        if("5".equals(type)){
            map.put("goods_id",goods_id);
        }else if("6".equals(type)){
            map.put("service_id",goods_id);
        }
        SubjectPost post=new SubjectPost(new ProgressSubscriber(listener,context,true,false,"登录中"),map);
        HttpManager.getInstance().addCoupon(post);
    }

    @Override
    public void getCouponList(String token, int page, HttpOnNextListener listener) {
        Map<String,Object> map=new HashMap<>();
        map.put("token",token);
        map.put("p",page);
        map.put("per",10);
        SubjectPost post=new SubjectPost(new ProgressSubscriber(listener,context,false,false,"登录中"),map);
        HttpManager.getInstance().getCouponList(post);
    }

    @Override
    public void delCoupon(String token, String coupon_id, HttpOnNextListener listener) {
        Map<String,Object> map=new HashMap<>();
        map.put("token",token);
        map.put("coupon_id",coupon_id);
        SubjectPost post=new SubjectPost(new ProgressSubscriber(listener,context,true,false,"登录中"),map);
        HttpManager.getInstance().delCoupon(post);
    }

    @Override
    public void editCoupon(String token, String coupon_id, String name, String money, String condition_money, String all_num, String limit_num, String send_start_time, String send_end_time, String use_start_time, String use_end_time, String type, String goods_id, HttpOnNextListener listener) {
        Map<String,Object> map=new HashMap<>();
        map.put("token",token);
        map.put("coupon_id",coupon_id);
        map.put("name",name);
        map.put("money",money);
        map.put("condition_money",condition_money);
        map.put("all_num",all_num);
        map.put("limit_num",limit_num);
        map.put("send_start_time",send_start_time);
        map.put("send_end_time",send_end_time);
        map.put("use_start_time",use_start_time);
        map.put("use_end_time",use_end_time);
        map.put("type",type);
        if("5".equals(type)){
            map.put("goods_id",goods_id);
        }else if("6".equals(type)){
            map.put("service_id",goods_id);
        }
        SubjectPost post=new SubjectPost(new ProgressSubscriber(listener,context,true,false,"登录中"),map);
        HttpManager.getInstance().editCoupon(post);
    }
}
